var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var UI_BulletMove_UIBindings = require("AA_UI_BulletMove_UIBindings");
var BundleConfig = require("AA_BundleConfig");
var ResKeeper = require("AA_ResKeeper");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var NodePoolMag = require("AA_NodePoolMag");
var BuffMag = require("AA_BuffMag");
var UI_BulletBomb = require("AA_UI_BulletBomb");
var LogManager = require("AA_LogManager");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_BulletMove = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.bulletId = 1;
    t.img = null;
    t.attack = 0;
    t.attackfang = null;
    t.isbaoji = false;
    t.isbisha = false;
    t.nowpos = null;
    t.issend = false;
    t.moveindex = 5;
    t.isChaoJi = false;
    t.languajiaodus = [];
    t.chongjiNode = null;
    t.bulletspeed = 7;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.initBullet = function (e) {
    return __awaiter(this, undefined, undefined, function () {
      var t;
      var o;
      var n;
      var i;
      return __generator(this, function (a) {
        switch (a.label) {
          case 0:
            this.node.angle = 0;
            this.attack = e.attack;
            this.attackfang = e.playerId;
            this.isbaoji = e.isbaoji;
            this.isbisha = e.isbisha;
            this.moveindex = 5;
            this.node.scale = 1;
            this.isChaoJi = false;
            this.cleanChongJiEff();
            if (BuffMag.BuffMgr.getLiuLianBuff(this.attackfang)) {
              this.isChaoJi = true;
              this.node.scale = 1.7;
              this.addChongJiEff();
            }
            this.issend = true;
            this.languajiaodus = [];
            if (BuffMag.BuffMgr.getLiuLianBomb(this.attackfang)) {
              t = this.getThreeUniqueRandomNumbers([0, 200], [300, 360]);
              for (o = 0; o < t.length; o++) {
                this.languajiaodus.push({
                  jiaodu: t[o],
                  ishave: false
                });
              }
            }
            n = 1;
            e && 4 == e.playerLevel && (n = 5);
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player7_" + n, cc.SpriteFrame)];
          case 1:
            i = a.sent();
            this.img.spriteFrame = i;
            LogManager.LogMgr.info("当前随机角度", this.languajiaodus);
            return [2];
        }
      });
    });
  };
  _creator.prototype.onDisable = function () {
    this.cleanChongJiEff();
  };
  _creator.prototype.getBiSha = function () {
    return this.isbisha;
  };
  _creator.prototype.addChongJiEff = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      return __generator(this, function (t) {
        switch (t.label) {
          case 0:
            this.chongjiNode = NodePoolMag.NodePoolMag.instance.getNode("chongji");
            if (this.chongjiNode) {
              return [3, 2];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "prefabs/effpre/UI_ChongJi", cc.Prefab)];
            }
          case 1:
            e = t.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("chongji", 1, e);
            this.chongjiNode = NodePoolMag.NodePoolMag.instance.getNode("chongji");
            t.label = 2;
          case 2:
            this.chongjiNode.x = -40;
            this.chongjiNode.y = 0;
            this.auto_ui.node_effNode.addChild(this.chongjiNode);
            return [2];
        }
      });
    });
  };
  _creator.prototype.cleanChongJiEff = function () {
    if (this.chongjiNode) {
      NodePoolMag.NodePoolMag.instance.recycleNode("chongji", this.chongjiNode);
      this.chongjiNode = null;
    }
  };
  _creator.prototype.hideBullet = function () {
    this.issend = false;
    this.cleanChongJiEff();
    NodePoolMag.NodePoolMag.instance.recycleNode("bullet_3", this.node);
  };
  _creator.prototype.getRandomInt = function (e, t) {
    return Math.floor(Math.random() * (t - e + 1)) + e;
  };
  _creator.prototype.getThreeUniqueRandomNumbers = function (e, t) {
    var o = [];
    for (var n = e[0]; n <= e[1]; n++) {
      o.push(n);
    }
    for (n = t[0]; n <= t[1]; n++) {
      o.push(n);
    }
    for (var i = []; i.length < 2;) {
      var a = o[this.getRandomInt(0, o.length - 1)];
      i.includes(a) || i.push(a);
    }
    return i;
  };
  _creator.prototype.createLanGua = function () {
    var e = this;
    var t = this.node.parent;
    if (t) {
      var o = cc.Vec2.subtract(cc.v2(), this.node.getPosition(), t.getPosition());
      var n = Math.atan2(o.y, o.x);
      var i = 180 / Math.PI * n + 180;
      var a = function (t) {
        var o = r.languajiaodus[t];
        if (!o.ishave) {
          var n = o.jiaodu;
          if (Math.abs(i - n) <= 10) {
            o.ishave = true;
            var a = r.node.x;
            var c = r.node.y;
            r.scheduleOnce(function () {
              e.createBulletBomb(cc.v2(a, c));
            });
            r.languajiaodus[t] = o;
          }
        }
      };
      var r = this;
      for (var c = 0; c < this.languajiaodus.length; c++) {
        a(c);
      }
    }
  };
  _creator.prototype.createBulletBomb = function (e) {
    return __awaiter(this, undefined, undefined, function () {
      var t;
      var o;
      var n;
      var i;
      return __generator(this, function (a) {
        switch (a.label) {
          case 0:
            if (t = NodePoolMag.NodePoolMag.instance.getNode("bullet_2")) {
              return [3, 2];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "prefabs/bullet/bullet2", cc.Prefab)];
            }
          case 1:
            o = a.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("bullet_2", 1, o);
            t = NodePoolMag.NodePoolMag.instance.getNode("bullet_2");
            a.label = 2;
          case 2:
            t.x = e.x;
            t.y = e.y;
            GameGlobalVariable.GameGlobalVariable.languaNode.addChild(t);
            t.scale = 0;
            cc.tween(t).to(.2, {
              scale: 1
            }).start();
            n = t.getComponent(UI_BulletBomb.default);
            i = BuffMag.BuffMgr.getLiuLianBomb(this.attackfang);
            n.initBullet({
              attack: this.attack * GameGlobalVariable.GameGlobalVariable.liulianlanguabomb,
              attackfanwei: i.value[0],
              playerId: this.attackfang,
              skinlevel: 4,
              isbaoji: this.isbaoji
            }, cc.v2(e.x, e.y));
            return [2];
        }
      });
    });
  };
  _creator.prototype.sendBullet1 = function () {
    var e = this;
    var t = GameGlobalVariable.GameGlobalVariable.paths.children[this.moveindex];
    if (t) {
      if (5 == this.moveindex) {
        this.node.x = t.x;
        this.node.y = t.y;
        this.moveindex -= 1;
      } else {
        !function o(n) {
          if (t = GameGlobalVariable.GameGlobalVariable.paths.children[e.moveindex]) {
            var i = cc.Vec2.subtract(cc.v2(), cc.v2(t.x, t.y), e.node.getPosition());
            var a = Math.atan2(i.y, i.x);
            var r = cc.Vec2.distance(e.node.getPosition(), cc.v2(t.x, t.y));
            var c = n;
            var s = 0;
            if (r < c) {
              s = c - r;
              c = r;
            }
            e.node.x += Math.cos(a) * c;
            e.node.y += Math.sin(a) * c;
            if (s > 0) {
              e.moveindex -= 1;
              o(s);
            }
          } else {
            e.hideBullet();
          }
        }(this.getBulletSpeed());
      }
      this.updateDir();
    } else {
      this.hideBullet();
    }
  };
  _creator.prototype.updateDir = function () {
    switch (this.moveindex) {
      case 4:
        this.auto_ui.node_effNode.angle = 0;
        break;
      case 3:
        this.auto_ui.node_effNode.angle = -90;
        break;
      case 2:
        this.auto_ui.node_effNode.angle = 180;
        break;
      case 1:
        this.auto_ui.node_effNode.angle = 90;
        break;
      case 0:
        this.auto_ui.node_effNode.angle = 0;
    }
  };
  _creator.prototype.getBulletAttack = function () {
    return this.attack;
  };
  _creator.prototype.getBulletSpeed = function () {
    this.bulletspeed = this.bulletspeed * GameGlobalVariable.GameGlobalVariable.jiasuState;
    return this.bulletspeed;
  };
  _creator.prototype.onUpdate = function () {
    if (this.issend) {
      this.node.children[0].angle += this.getBulletSpeed();
      this.sendBullet1();
      this.attackfang.playerInfo.equipLevel >= 4 && this.createLanGua();
    }
  };
  __decorate([_property(UI_BulletMove_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  __decorate([_property()], _creator.prototype, "bulletId", undefined);
  __decorate([_property(cc.Sprite)], _creator.prototype, "img", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_BulletMove;